* @iter: The uninitialized #GtkTreeIter.
* @path: The #GtkTreePath.
*
- * Sets @iter to a valid iterator pointing to @path. If the model does not
- * provide an implementation of this function, it is implemented in terms of
- * @gtk_tree_model_iter_nth_child.
+ * Sets @iter to a valid iterator pointing to @path.
*
* Return value: TRUE, if @iter was set.
**/
GtkTreeIter *iter,
GtkTreePath *path)
{
- GtkTreeIter parent;
- gint *indices;
- gint depth, i;
-
g_return_val_if_fail (GTK_IS_TREE_MODEL (tree_model), FALSE);
g_return_val_if_fail (iter != NULL, FALSE);
g_return_val_if_fail (path != NULL, FALSE);
+ g_return_val_if_fail (GTK_TREE_MODEL_GET_IFACE (tree_model)->get_iter != NULL, FALSE);
- if (GTK_TREE_MODEL_GET_IFACE (tree_model)->get_iter != NULL)
- return (* GTK_TREE_MODEL_GET_IFACE (tree_model)->get_iter) (tree_model, iter, path);
-
- indices = gtk_tree_path_get_indices (path);
- depth = gtk_tree_path_get_depth (path);
-
- g_return_val_if_fail (depth > 0, FALSE);
-
- if (! gtk_tree_model_iter_nth_child (tree_model, iter, NULL, indices[0]))
- return FALSE;
-
- for (i = 1; i < depth; i++)
- {
- parent = *iter;
- if (! gtk_tree_model_iter_nth_child (tree_model, iter, &parent, indices[i]))
- return FALSE;
- }
-
- return TRUE;
+ return (* GTK_TREE_MODEL_GET_IFACE (tree_model)->get_iter) (tree_model, iter, path);
}
* gtk_tree_row_reference_get_path:
* @reference: A #GtkTreeRowReference
*
- * Returns a path that the row reference currently points to, or NULL if
+ * Returns a path that the row reference currently points to, or NULL if the
+ * path pointed to is no longer valid.
*
* Return value: A current path, or NULL.
**/
static gint gtk_tree_store_get_n_columns (GtkTreeModel *tree_model);
static GType gtk_tree_store_get_column_type (GtkTreeModel *tree_model,
gint index);
+static gboolean gtk_tree_store_get_iter (GtkTreeModel *tree_model,
+ GtkTreeIter *iter,
+ GtkTreePath *path);
static GtkTreePath *gtk_tree_store_get_path (GtkTreeModel *tree_model,
GtkTreeIter *iter);
static void gtk_tree_store_get_value (GtkTreeModel *tree_model,
iface->get_flags = gtk_tree_store_get_flags;
iface->get_n_columns = gtk_tree_store_get_n_columns;
iface->get_column_type = gtk_tree_store_get_column_type;
+ iface->get_iter = gtk_tree_store_get_iter;
iface->get_path = gtk_tree_store_get_path;
iface->get_value = gtk_tree_store_get_value;
iface->iter_next = gtk_tree_store_iter_next;
return GTK_TREE_STORE (tree_model)->column_headers[index];
}
+static gboolean
+gtk_tree_store_get_iter (GtkTreeModel *tree_model,
+ GtkTreeIter *iter,
+ GtkTreePath *path)
+{
+ GtkTreeStore *tree_store = (GtkTreeStore *) tree_model;
+ GtkTreeIter parent;
+ gint *indices;
+ gint depth, i;
+
+ g_return_val_if_fail (GTK_IS_TREE_STORE (tree_store), FALSE);
+
+ indices = gtk_tree_path_get_indices (path);
+ depth = gtk_tree_path_get_depth (path);
+
+ g_return_val_if_fail (depth > 0, FALSE);
+
+ parent.stamp = tree_store->stamp;
+ parent.user_data = tree_store->root;
+
+ if (! gtk_tree_model_iter_nth_child (tree_model, iter, &parent, indices[0]))
+ return FALSE;
+
+ for (i = 1; i < depth; i++)
+ {
+ parent = *iter;
+ if (! gtk_tree_model_iter_nth_child (tree_model, iter, &parent, indices[i]))
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
static GtkTreePath *
gtk_tree_store_get_path (GtkTreeModel *tree_model,
GtkTreeIter *iter)
gboolean open_all);
static void gtk_tree_view_real_set_cursor (GtkTreeView *tree_view,
GtkTreePath *path,
- gboolean clear_and_select,
- GdkModifierType state);
+ gboolean clear_and_select);
static GtkContainerClass *parent_class = NULL;
tree_view->priv->press_start_y = event->y;
}
- gtk_tree_view_real_set_cursor (tree_view, path, TRUE, event->state);
+ gtk_tree_view_real_set_cursor (tree_view, path, TRUE);
if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
{
}
if (tree_view->priv->selection->type == GTK_TREE_SELECTION_SINGLE)
- gtk_tree_view_real_set_cursor (tree_view, cursor_path, TRUE, 0);
+ gtk_tree_view_real_set_cursor (tree_view, cursor_path, TRUE);
else
- gtk_tree_view_real_set_cursor (tree_view, cursor_path, FALSE, 0);
+ gtk_tree_view_real_set_cursor (tree_view, cursor_path, FALSE);
gtk_tree_path_free (cursor_path);
-
}
static void
GtkTreePath *cursor_path = NULL;
cursor_path = NULL;
- if (tree_view->priv->cursor)
- cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
-
- if (cursor_path == NULL)
+ if (!gtk_tree_row_reference_valid (tree_view->priv->cursor))
return;
+ cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
_gtk_tree_view_find_node (tree_view, cursor_path,
&cursor_tree, &cursor_node);
+ gtk_tree_path_free (cursor_path);
if (count == -1)
_gtk_rbtree_prev_full (cursor_tree, cursor_node,
if (new_cursor_node)
{
- gtk_tree_view_queue_draw_path (tree_view, cursor_path, NULL);
- gtk_tree_path_free (cursor_path);
-
cursor_path = _gtk_tree_view_find_path (tree_view, new_cursor_tree, new_cursor_node);
- if (!tree_view->priv->in_free_motion)
- _gtk_tree_selection_internal_select_node (tree_view->priv->selection,
- new_cursor_node,
- new_cursor_tree,
- cursor_path,
- tree_view->priv->in_extended_selection?GDK_SHIFT_MASK:0);
- gtk_tree_row_reference_free (tree_view->priv->cursor);
- tree_view->priv->cursor = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, cursor_path);
- gtk_tree_view_clamp_node_visible (tree_view, new_cursor_tree, new_cursor_node);
+ gtk_tree_view_real_set_cursor (tree_view, cursor_path, TRUE);
+ gtk_tree_path_free (cursor_path);
}
else
{
}
gtk_widget_grab_focus (GTK_WIDGET (tree_view));
- gtk_tree_view_queue_draw_path (tree_view, cursor_path, NULL);
- gtk_tree_path_free (cursor_path);
}
static void
gtk_tree_view_move_cursor_page_up_down (GtkTreeView *tree_view,
gint count)
{
- g_print ("gtk_tree_view_move_cursor_page_up_down\n");
+ GtkRBTree *cursor_tree = NULL;
+ GtkRBNode *cursor_node = NULL;
+ GtkTreePath *cursor_path = NULL;
+ gint y;
+ gint vertical_separator;
+
+ if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
+ cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
+ else
+ /* This is sorta weird. Focus in should give us a cursor */
+ return;
+
+ gtk_widget_style_get (GTK_WIDGET (tree_view), "vertical_separator", &vertical_separator, NULL);
+ _gtk_tree_view_find_node (tree_view, cursor_path,
+ &cursor_tree, &cursor_node);
+
+ gtk_tree_path_free (cursor_path);
+
+ g_return_if_fail (cursor_node != NULL);
+
+ y = CELL_FIRST_PIXEL (tree_view, cursor_tree, cursor_node, vertical_separator);
+ y += count * tree_view->priv->vadjustment->page_size;
+ y = CLAMP (y, (gint)tree_view->priv->vadjustment->lower, (gint)tree_view->priv->vadjustment->upper - vertical_separator);
+
+ _gtk_rbtree_find_offset (tree_view->priv->tree, y, &cursor_tree, &cursor_node);
+ cursor_path = _gtk_tree_view_find_path (tree_view, cursor_tree, cursor_node);
+ g_return_if_fail (cursor_path != NULL);
+ gtk_tree_view_real_set_cursor (tree_view,
+ cursor_path,
+ TRUE);
}
static void
g_print ("gtk_tree_view_move_cursor_left_right\n");
- cursor_path = NULL;
- if (tree_view->priv->cursor)
+ if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
-
- if (cursor_path == NULL)
+ else
return;
_gtk_tree_view_find_node (tree_view, cursor_path,
GtkRBTree *tree;
GtkRBNode *node;
- g_return_val_if_fail (GTK_IS_TREE_VIEW (tree_view), NULL);
- g_return_val_if_fail (path != NULL, NULL);
+ g_return_val_if_fail (GTK_IS_TREE_VIEW (tree_view), FALSE);
+ g_return_val_if_fail (path != NULL, FALSE);
_gtk_tree_view_find_node (tree_view, path, &tree, &node);
if (node == NULL)
- return NULL;
+ return FALSE;
return (node->children != NULL);
}
static void
gtk_tree_view_real_set_cursor (GtkTreeView *tree_view,
GtkTreePath *path,
- gboolean clear_and_select,
- GdkModifierType state)
+ gboolean clear_and_select)
{
GtkRBTree *tree = NULL;
GtkRBNode *node = NULL;
- if (tree_view->priv->cursor)
- gtk_tree_row_reference_free (tree_view->priv->cursor);
+ if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
+ {
+ GtkTreePath *cursor_path;
+ cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
+ gtk_tree_view_queue_draw_path (tree_view, cursor_path, NULL);
+ gtk_tree_path_free (cursor_path);
+ }
+ gtk_tree_row_reference_free (tree_view->priv->cursor);
+
tree_view->priv->cursor = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
tree_view->priv->model,
path);
if (tree == NULL)
return;
- if (clear_and_select)
- {
- gtk_tree_selection_unselect_all (tree_view->priv->selection);
- _gtk_tree_selection_internal_select_node (tree_view->priv->selection,
- node, tree,
- path, state);
- }
+ if (clear_and_select && !tree_view->priv->in_free_motion)
+ _gtk_tree_selection_internal_select_node (tree_view->priv->selection,
+ node, tree, path,
+ tree_view->priv->in_extended_selection?GDK_SHIFT_MASK:0);
gtk_tree_view_clamp_node_visible (tree_view, tree, node);
gtk_tree_view_queue_draw_node (tree_view, tree, node, NULL);
}
g_return_if_fail (GTK_IS_TREE_VIEW (tree_view));
g_return_if_fail (path != NULL);
- gtk_tree_view_real_set_cursor (tree_view, path, TRUE, 0);
+ gtk_tree_view_real_set_cursor (tree_view, path, TRUE);
}